<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script>

  //sendData 从小到大排序
  var arr = [
    {msg: '12', sendData: '2018-10-22'},
    {msg: '12', sendData: '2018-10-21'},
    {msg: '12', sendData: '2018-10-20'},
    {msg: '12', sendData: '2018-10-23'},
    {msg: '12', sendData: '2018-10-24'},
    {msg: '12', sendData: '2018-10-25'},
    {msg: '12', sendData: '2018-10-26'},
    {msg: '12', sendData: '2018-10-27'},
  ];
  arr = arr.sort(function (a, b) {
    return a.sendData > b.sendData ? 1 : -1// 为什么是这样写？
  });
  var arr2 = [
    {num: 15},
    {num: 14},
    {num: 12},
    {num: 18},
    {num: 16}
  ];
  arr2 = arr2.sort(function (a, b) {
    return a.num - b.num
  });
  console.log(arr);
  console.log(arr2);
</script>
</body>
</html>